var commonUtil = {

    // UUID
    getUUID: function () {
        /**
         * @return {string}
         */
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4());
    },

    // es5 数组去重
    arrayUnip: function (array) {
        var arr = [];
        var flag = true;
        array.forEach(function (item) {
            if (item != item) {
                flag && arr.indexOf(item) === -1 ? arr.push(item) : '';
                flag = false;
            } else {
                arr.indexOf(item) === -1 ? arr.push(item) : ''
            }
        });
        return arr;
    },

    // 根据打印长度（中文2，英文1）截取字符串
    // 从中间往后遍历
    subStrForPrint1: function (str, len) {
        if (!str) {
            return "";
        }
        var str_sub = str;
        var r = /[^\x00-\xff]/g;
        if (str_sub.replace(r, "mm").length <= len) {
            return str;
        }
        var m = Math.floor(len / 2);
        for (var i = m; i < str_sub.length; i++) {
            if (str_sub.substr(0, i).replace(r, "mm").length >= len) {
                return str_sub.substr(0, i);
            }
        }
        return str;
    },

    // 从后往前遍历
    subStrForPrint2: function (str, len) {
        if (!str) {
            return "";
        }
        var str_sub = str;
        var r = /[^\x00-\xff]/g;
        if (str_sub.replace(r, "mm").length <= len) {
            return str;
        }
        for (var i = str_sub.length - 1; i >= 0; i--) {
            if (str_sub.substr(0, i).replace(r, "mm").length <= len) {
                return str_sub.substr(0, i);
            }
        }
        return str;
    },

    // 计算字符串长度(英文占1个字符，中文汉字占2个字符)
    getStrTrueLength: function (str) {
        var len = 0;
        for (var i = 0; i < str.length; i++) {
            if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
                len += 2;
            } else {
                len++;
            }
        }
        return len;
    },

    // 提取 字符串中的数字
    getNumFromString: function (text) {
        return text.replace(/[^0-9]/ig, "");
    },

    // 计算 运行时间
    runTime: function () {
        var start = new Date().getTime();

        // ...

        var end = new Date().getTime();
        console.log('操作结束！ 共耗时：' + (end - start) + 'ms');
    },
};